package org.elucid.collections;

import java.util.HashMap;
import java.util.LinkedHashMap;

/**
 * basic implementation of a BiDirectional Map
 * 
 * @author george
 *
 * @param <K>
 * @param <V>
 */
public class BiMap<K,V> extends LinkedHashMap<K,V> {

	public HashMap<V, K> inverseMap = new HashMap<V,K>();
	
	@Override
	public V put(K key, V value)
	{
		V val = super.put(key, value);
		inverseMap.put(value, key);
		
		return val;
	}
	
	@Override
	public V remove(Object key) {
		V value = super.remove(key);
		inverseMap.remove(value);
		
		return value;
	}

	public K removeValue(Object value) {
		K key = inverseMap.remove(value);
		this.remove(key);
		
		return key;
	}

	public K getKey(V value)
	{
		return inverseMap.get(value);
	}
	
	private static final long serialVersionUID = 3306498244607923296L;



	
	
}
